//iframe
function iframe()
{
	//根据屏幕及浏览器实际情况取的自动值
	var r=document.getElementById('rightpaniel');
	var iniHeight=screen.height-((screen.height-r.clientHeight)+40);

	//根据实际载入的页，设计屏幕容器的高度
	var fr = document.getElementById('frmright');
	fr.height=fr.contentWindow.document.body.scrollHeight+13;

	//判断容器应有高度
	if(iniHeight>fr.height) fr.height=iniHeight;
	

	//every load
	fr.onload = fr.onreadystatechange = function() 
	{	
		
		 if (this.readyState && this.readyState != 'complete') 
			return;
		 else
		 {				
			if(iniHeight>this.contentWindow.document.body.clientHeight)		
				this.height=iniHeight;
			else
			{				
				this.height=this.contentWindow.document.body.clientHeight+13;
			}		
		}
	};	
}

//clock		
function startTime()   
{   
	  var today=new Date()   
	  var years=today.getFullYear();   
	  var months=today.getMonth();   
	  var d=today.getDate()   
	  var h=today.getHours()   
	  var m=today.getMinutes()   
	  var s=today.getSeconds()   
	  // add a zero in front of numbers<10  
	  monthsmonths=months+1   
	  months=checkTime(months)   
	  d=checkTime(d)   
	  m=checkTime(m)   
	  s=checkTime(s)   
	  var weekday=new Array(7)   
	  weekday[0]="星期日"   
	  weekday[1]="星期一"   
	  weekday[2]=" 星期二"   
	  weekday[3]="星期三"   
	  weekday[4]="星期四"   
	  weekday[5]="星期五"   
	  weekday[6]=" 星期六"   
	  var w=weekday[today.getDay()]   
	  document.getElementById('datepaniel').innerHTML=years+" 年"+months+"月"+d+"日 "+w+" "+h+":"+m+":"+s;   
	  t=setTimeout('startTime()',1000)   
	  }   
	  function checkTime(i)   
	  {   
	  if (i<10)   
	  {i="0" + i}   
	  return i   
} 		

//loadmenu
function loadmenu()
{
	var menusData=MenusData;
	
	var parentTemplate = "";
	$.ajax({type:"get",
	url:"skins/template/menus/parent.html",
	async :false,
	success:function(data){
		parentTemplate = data;
		}   
	});
	
	var childTemplate = "";
	$.ajax({type:"get",
	url:"skins/template/menus/clild.html",
	async :false,
	success:function(msg){
		childTemplate = msg;
		}   
	});		
	
	var topMenusData="",leftMenusData="";
	for(var i=0;i<menusData.length;i++)
	{
		  var menuData=menusData[i];
		  topMenusData+=makeTopmenu(parentTemplate,menuData[0],i,menusData.length);	//生成主菜单
		  leftMenusData+=makeLeftmenu(childTemplate,menuData[1],i);					//生成子菜单
	}
  
	$('#topMenudataPaniel').html(topMenusData);
	$('#leftmenupaniel').html(leftMenusData);
	
	//#支持函数
	function makeTopmenu(template,data,orderid,count)
	{
		  template=template.replace(/\$\{href\}/ig,data.href);
		  template=template.replace(/\$\{label\}/ig,data.label);
		  template=template.replace(/\$\{orderid\}/ig,orderid);				
		  template=template.replace(/\$\{count\}/ig,count);		
		  return template;
	}
	
	function makeLeftmenu(template,data,orderid)
	{
		var insideTemplate=template.match(/<div[^>]*>\s*(<div[^>]*>[\s\S]*<\/div>)\s*<\/div>/)[1];
		var outsideTemplate=template.replace(/(<div[^>]*>\s*)(<div[^>]*>[\s\S]*<\/div>)(\s*<\/div>)/,"$1$tempInsidetemplate$3");
			if(orderid==0){
			  outsideTemplate=outsideTemplate.replace(/\$\{display\}/ig,"");
			}
			else{
			  outsideTemplate=outsideTemplate.replace(/\$\{display\}/ig,"none");
			}
			outsideTemplate=outsideTemplate.replace(/\$\{orderid\}/ig,orderid);

		var tempInsidetemplate="";
		for(var j=0;j<data.length;j++)
		{
			  var tempTemplate=insideTemplate;
			  tempTemplate=tempTemplate.replace(/\$\{href\}/ig,data[j].href);
			  tempTemplate=tempTemplate.replace(/\$\{label\}/ig,data[j].label);
			  tempTemplate=tempTemplate.replace(/\$\{orderid\}/ig,orderid);	
			  tempInsidetemplate+=tempTemplate;		  
		}
		return outsideTemplate.replace(/\$tempInsidetemplate/g,tempInsidetemplate);
	}
}

//switch menu
function disp(n, count) 
{
	for (var i = 0; i < count; i++) {
		if (!document.getElementById("leftmenu_" + i)) return;
		document.getElementById("leftmenu_" + i).style.display = 'none';
	}
	document.getElementById("leftmenu_" + n).style.display = '';
}	

//keybord 
document.onkeydown = function(e)
{
	var code; 
	if(!e)  var e=window.event; 
	
	if(e.keyCode) 
	{   
		code=e.keyCode; 
	} 
	else if(e.which) 
	{ 
		code   =   e.which; 
	}
	
	if(e.ctrlKey&&e.altKey&&e.shiftKey&&code==8)
	{		
		 switch(window.prompt("Please input the Cedar of System command.","").toLowerCase())
		 {
		  	case "execute jetsql":
				var fr = document.getElementById("frmright");
				fr.src="module/aide/executeJetSql.aspx";		
			break;
			default:
				alert("不是内部命令或外部命令，也不是可运行的Web工具。");
	       }
		 return false;
	}
}

var Timer = 0;